﻿package  birdry.utils	{
	
	//	import birdry.utils.MovieClipUtil;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import gs.TweenMax;
	import gs.easing.Linear;
	
	public class TransitionUtil	extends Sprite	{
		
		public static function alphaCell( obj:DisplayObject, width:uint, height:uint, func:Function=null, time:Number=0.5, delay:Number = 1): void	{
			var i:uint;
			var u:uint;
			var container:Sprite = new Sprite();
			var bitmapArr:Array = BitmapUtil.returnBitmapSplit(obj, width, height);
			
			obj.visible = false;
			Object(obj.parent).addChild( container );
			container.x = obj.x;
			container.y = obj.y;
			
			for (i = 0; i < bitmapArr.length; ++i)	{
				for (u = 0; u < bitmapArr[i].length; ++u)	{
					var tempBM:Bitmap = new Bitmap( bitmapArr[i][u] );
					container.addChild( tempBM );
					tempBM.x = i * width;
					tempBM.y = u * height;
					tempBM.alpha = 0;
					TweenMax.to(tempBM, time, { alpha:1, delay:Math.random() * delay } );
				}
			}
			TweenMax.to(obj, time + delay, { onComplete:transitionComplete } );
			function transitionComplete(): void	{
				DisplayObjectUtil.removeDisplayObject(container);
				obj.visible = true;
				if(func != null)	func();
			}
		}
	}
}

